package com.zhs.gccs.activity.gb;

import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnErrorListener;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.zhs.gccs.R;
import com.zhs.gccs.base.BaseActivity;
import com.zhs.gccs.utils.OnNoDoubleClickListener;
import com.zhs.gccs.utils.ToastUtils;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PDFActivity extends BaseActivity implements OnPageChangeListener , OnLoadCompleteListener {
    public static String intent_title = "title";
    public static String intent_url = "url";
    private String title;
    private String url;

    @BindView(R.id.iv_back)
    View iv_back;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.pdfView)
    PDFView pdfView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_pdf);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        ButterKnife.bind(this);
        iv_back.setOnClickListener(new OnNoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                finish();
            }
        });
        title = getIntent().getStringExtra(intent_title);
        url = getIntent().getStringExtra(intent_url);
        tv_title.setText(title);
        pdfView.setEnabled(false);
        pdfView.fromFile(new File(url)) .defaultPage(0)
                .onPageChange(this)
                .onLoad(this)
                .onError(new OnErrorListener() {
                    @Override
                    public void onError(Throwable t) {
                        ToastUtils.toast("文件损坏，加载文件失败失败");
                    }
                })
                .load();
        pdfView.setEnabled(true);
    }

    @Override
    public void onPageChanged(int page, int pageCount) {

    }

    @Override
    public void loadComplete(int nbPages) {

    }
}
